home *** CD-ROM | disk | FTP | other *** search
/ Freelog 121 / FreelogMagazineJuilletAout2014-No121.iso / Outils / Adobe-Air / adobe-air_13.exe / [0] / setup.swf / scripts / mx / containers / utilityClasses / BoxLayout.as < prev    next >
Text File  |  2014-03-27  |  10KB  |  279 lines

  1. package mx.containers.utilityClasses
  2. {
  3.    import mx.containers.BoxDirection;
  4.    import mx.controls.scrollClasses.ScrollBar;
  5.    import mx.core.Container;
  6.    import mx.core.EdgeMetrics;
  7.    import mx.core.IUIComponent;
  8.    import mx.core.ScrollPolicy;
  9.    import mx.core.mx_internal;
  10.    
  11.    use namespace mx_internal;
  12.    
  13.    public class BoxLayout extends Layout
  14.    {
  15.       
  16.       mx_internal static const VERSION:String = "3.0.0.0";
  17.        
  18.       
  19.       public var direction:String = "vertical";
  20.       
  21.       public function BoxLayout()
  22.       {
  23.          super();
  24.       }
  25.       
  26.       private function isVertical() : Boolean
  27.       {
  28.          return direction != BoxDirection.HORIZONTAL;
  29.       }
  30.       
  31.       mx_internal function getHorizontalAlignValue() : Number
  32.       {
  33.          var _loc1_:String = target.getStyle("horizontalAlign");
  34.          if(_loc1_ == "center")
  35.          {
  36.             return 0.5;
  37.          }
  38.          if(_loc1_ == "right")
  39.          {
  40.             return 1;
  41.          }
  42.          return 0;
  43.       }
  44.       
  45.       override public function updateDisplayList(param1:Number, param2:Number) : void
  46.       {
  47.          var _loc16_:Number = NaN;
  48.          var _loc17_:int = 0;
  49.          var _loc18_:Number = NaN;
  50.          var _loc19_:Number = NaN;
  51.          var _loc20_:Number = NaN;
  52.          var _loc21_:int = 0;
  53.          var _loc22_:IUIComponent = null;
  54.          var _loc23_:IUIComponent = null;
  55.          var _loc24_:Number = NaN;
  56.          var _loc25_:Number = NaN;
  57.          var _loc26_:Number = NaN;
  58.          var _loc27_:Number = NaN;
  59.          var _loc3_:Container = super.target;
  60.          var _loc4_:int;
  61.          if((_loc4_ = _loc3_.numChildren) == 0)
  62.          {
  63.             return;
  64.          }
  65.          var _loc5_:EdgeMetrics = _loc3_.viewMetricsAndPadding;
  66.          var _loc6_:Number = _loc3_.getStyle("paddingLeft");
  67.          var _loc7_:Number = _loc3_.getStyle("paddingTop");
  68.          var _loc8_:Number = getHorizontalAlignValue();
  69.          var _loc9_:Number = getVerticalAlignValue();
  70.          var _loc10_:Number = _loc3_.scaleX > 0 && _loc3_.scaleX != 1 ? Number(_loc3_.minWidth / Math.abs(_loc3_.scaleX)) : Number(_loc3_.minWidth);
  71.          var _loc11_:Number = _loc3_.scaleY > 0 && _loc3_.scaleY != 1 ? Number(_loc3_.minHeight / Math.abs(_loc3_.scaleY)) : Number(_loc3_.minHeight);
  72.          var _loc12_:Number = Math.max(param1,_loc10_) - _loc5_.right - _loc5_.left;
  73.          var _loc13_:Number = Math.max(param2,_loc11_) - _loc5_.bottom - _loc5_.top;
  74.          var _loc14_:ScrollBar = _loc3_.horizontalScrollBar;
  75.          var _loc15_:ScrollBar = _loc3_.verticalScrollBar;
  76.          if(_loc4_ == 1)
  77.          {
  78.             _loc24_ = (_loc23_ = IUIComponent(_loc3_.getChildAt(0))).percentWidth;
  79.             _loc25_ = _loc23_.percentHeight;
  80.             if(_loc24_)
  81.             {
  82.                _loc26_ = Math.max(_loc23_.minWidth,Math.min(_loc23_.maxWidth,_loc24_ >= 100 ? Number(_loc12_) : Number(_loc12_ * _loc24_ / 100)));
  83.             }
  84.             else
  85.             {
  86.                _loc26_ = _loc23_.getExplicitOrMeasuredWidth();
  87.             }
  88.             if(_loc25_)
  89.             {
  90.                _loc27_ = Math.max(_loc23_.minHeight,Math.min(_loc23_.maxHeight,_loc25_ >= 100 ? Number(_loc13_) : Number(_loc13_ * _loc25_ / 100)));
  91.             }
  92.             else
  93.             {
  94.                _loc27_ = _loc23_.getExplicitOrMeasuredHeight();
  95.             }
  96.             if(_loc23_.scaleX == 1 && _loc23_.scaleY == 1)
  97.             {
  98.                _loc23_.setActualSize(Math.floor(_loc26_),Math.floor(_loc27_));
  99.             }
  100.             else
  101.             {
  102.                _loc23_.setActualSize(_loc26_,_loc27_);
  103.             }
  104.             if(_loc15_ != null && _loc3_.verticalScrollPolicy == ScrollPolicy.AUTO)
  105.             {
  106.                _loc12_ += _loc15_.minWidth;
  107.             }
  108.             if(_loc14_ != null && _loc3_.horizontalScrollPolicy == ScrollPolicy.AUTO)
  109.             {
  110.                _loc13_ += _loc14_.minHeight;
  111.             }
  112.             _loc20_ = (_loc12_ - _loc23_.width) * _loc8_ + _loc6_;
  113.             _loc19_ = (_loc13_ - _loc23_.height) * _loc9_ + _loc7_;
  114.             _loc23_.move(Math.floor(_loc20_),Math.floor(_loc19_));
  115.          }
  116.          else if(isVertical())
  117.          {
  118.             _loc16_ = _loc3_.getStyle("verticalGap");
  119.             _loc17_ = _loc4_;
  120.             _loc21_ = 0;
  121.             while(_loc21_ < _loc4_)
  122.             {
  123.                if(!IUIComponent(_loc3_.getChildAt(_loc21_)).includeInLayout)
  124.                {
  125.                   _loc17_--;
  126.                }
  127.                _loc21_++;
  128.             }
  129.             _loc18_ = Flex.flexChildHeightsProportionally(_loc3_,_loc13_ - (_loc17_ - 1) * _loc16_,_loc12_);
  130.             if(_loc14_ != null && _loc3_.horizontalScrollPolicy == ScrollPolicy.AUTO)
  131.             {
  132.                _loc18_ += _loc14_.minHeight;
  133.             }
  134.             if(_loc15_ != null && _loc3_.verticalScrollPolicy == ScrollPolicy.AUTO)
  135.             {
  136.                _loc12_ += _loc15_.minWidth;
  137.             }
  138.             _loc19_ = _loc7_ + _loc18_ * _loc9_;
  139.             _loc21_ = 0;
  140.             while(_loc21_ < _loc4_)
  141.             {
  142.                _loc22_ = IUIComponent(_loc3_.getChildAt(_loc21_));
  143.                _loc20_ = (_loc12_ - _loc22_.width) * _loc8_ + _loc6_;
  144.                _loc22_.move(Math.floor(_loc20_),Math.floor(_loc19_));
  145.                if(_loc22_.includeInLayout)
  146.                {
  147.                   _loc19_ += _loc22_.height + _loc16_;
  148.                }
  149.                _loc21_++;
  150.             }
  151.          }
  152.          else
  153.          {
  154.             _loc16_ = _loc3_.getStyle("horizontalGap");
  155.             _loc17_ = _loc4_;
  156.             _loc21_ = 0;
  157.             while(_loc21_ < _loc4_)
  158.             {
  159.                if(!IUIComponent(_loc3_.getChildAt(_loc21_)).includeInLayout)
  160.                {
  161.                   _loc17_--;
  162.                }
  163.                _loc21_++;
  164.             }
  165.             _loc18_ = Flex.flexChildWidthsProportionally(_loc3_,_loc12_ - (_loc17_ - 1) * _loc16_,_loc13_);
  166.             if(_loc14_ != null && _loc3_.horizontalScrollPolicy == ScrollPolicy.AUTO)
  167.             {
  168.                _loc13_ += _loc14_.minHeight;
  169.             }
  170.             if(_loc15_ != null && _loc3_.verticalScrollPolicy == ScrollPolicy.AUTO)
  171.             {
  172.                _loc18_ += _loc15_.minWidth;
  173.             }
  174.             _loc20_ = _loc6_ + _loc18_ * _loc8_;
  175.             _loc21_ = 0;
  176.             while(_loc21_ < _loc4_)
  177.             {
  178.                _loc22_ = IUIComponent(_loc3_.getChildAt(_loc21_));
  179.                _loc19_ = (_loc13_ - _loc22_.height) * _loc9_ + _loc7_;
  180.                _loc22_.move(Math.floor(_loc20_),Math.floor(_loc19_));
  181.                if(_loc22_.includeInLayout)
  182.                {
  183.                   _loc20_ += _loc22_.width + _loc16_;
  184.                }
  185.                _loc21_++;
  186.             }
  187.          }
  188.       }
  189.       
  190.       mx_internal function getVerticalAlignValue() : Number
  191.       {
  192.          var _loc1_:String = target.getStyle("verticalAlign");
  193.          if(_loc1_ == "middle")
  194.          {
  195.             return 0.5;
  196.          }
  197.          if(_loc1_ == "bottom")
  198.          {
  199.             return 1;
  200.          }
  201.          return 0;
  202.       }
  203.       
  204.       mx_internal function heightPadding(param1:Number) : Number
  205.       {
  206.          var _loc2_:EdgeMetrics = target.viewMetricsAndPadding;
  207.          var _loc3_:Number = _loc2_.top + _loc2_.bottom;
  208.          if(param1 > 1 && isVertical())
  209.          {
  210.             _loc3_ += target.getStyle("verticalGap") * (param1 - 1);
  211.          }
  212.          return _loc3_;
  213.       }
  214.       
  215.       mx_internal function widthPadding(param1:Number) : Number
  216.       {
  217.          var _loc2_:EdgeMetrics = target.viewMetricsAndPadding;
  218.          var _loc3_:Number = _loc2_.left + _loc2_.right;
  219.          if(param1 > 1 && isVertical() == false)
  220.          {
  221.             _loc3_ += target.getStyle("horizontalGap") * (param1 - 1);
  222.          }
  223.          return _loc3_;
  224.       }
  225.       
  226.       override public function measure() : void
  227.       {
  228.          var _loc1_:Container = null;
  229.          var _loc10_:Number = NaN;
  230.          var _loc11_:Number = NaN;
  231.          var _loc12_:IUIComponent = null;
  232.          var _loc13_:Number = NaN;
  233.          var _loc14_:Number = NaN;
  234.          _loc1_ = super.target;
  235.          var _loc2_:Boolean = isVertical();
  236.          var _loc3_:Number = 0;
  237.          var _loc4_:Number = 0;
  238.          var _loc5_:Number = 0;
  239.          var _loc6_:Number = 0;
  240.          var _loc7_:int;
  241.          var _loc8_:int = _loc7_ = _loc1_.numChildren;
  242.          var _loc9_:int = 0;
  243.          while(_loc9_ < _loc7_)
  244.          {
  245.             if(!(_loc12_ = IUIComponent(_loc1_.getChildAt(_loc9_))).includeInLayout)
  246.             {
  247.                _loc8_--;
  248.             }
  249.             else
  250.             {
  251.                _loc13_ = _loc12_.getExplicitOrMeasuredWidth();
  252.                _loc14_ = _loc12_.getExplicitOrMeasuredHeight();
  253.                if(_loc2_)
  254.                {
  255.                   _loc3_ = Math.max(!isNaN(_loc12_.percentWidth) ? Number(_loc12_.minWidth) : Number(_loc13_),_loc3_);
  256.                   _loc5_ = Math.max(_loc13_,_loc5_);
  257.                   _loc4_ += !isNaN(_loc12_.percentHeight) ? _loc12_.minHeight : _loc14_;
  258.                   _loc6_ += _loc14_;
  259.                }
  260.                else
  261.                {
  262.                   _loc3_ += !isNaN(_loc12_.percentWidth) ? _loc12_.minWidth : _loc13_;
  263.                   _loc5_ += _loc13_;
  264.                   _loc4_ = Math.max(!isNaN(_loc12_.percentHeight) ? Number(_loc12_.minHeight) : Number(_loc14_),_loc4_);
  265.                   _loc6_ = Math.max(_loc14_,_loc6_);
  266.                }
  267.             }
  268.             _loc9_++;
  269.          }
  270.          _loc10_ = widthPadding(_loc8_);
  271.          _loc11_ = heightPadding(_loc8_);
  272.          _loc1_.measuredMinWidth = _loc3_ + _loc10_;
  273.          _loc1_.measuredMinHeight = _loc4_ + _loc11_;
  274.          _loc1_.measuredWidth = _loc5_ + _loc10_;
  275.          _loc1_.measuredHeight = _loc6_ + _loc11_;
  276.       }
  277.    }
  278. }
  279.